/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.hellodoctor.slayer.model.impl;

import com.hellodoctor.slayer.model.Appointment;
import com.hellodoctor.slayer.model.AppointmentModel;
import com.hellodoctor.slayer.model.AppointmentSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Appointment service. Represents a row in the &quot;hd_Appointment&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.hellodoctor.slayer.model.AppointmentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AppointmentImpl}.
 * </p>
 *
 * @author Shahbaj
 * @see AppointmentImpl
 * @see com.hellodoctor.slayer.model.Appointment
 * @see com.hellodoctor.slayer.model.AppointmentModel
 * @generated
 */
@JSON(strict = true)
public class AppointmentModelImpl extends BaseModelImpl<Appointment>
	implements AppointmentModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a appointment model instance should use the {@link com.hellodoctor.slayer.model.Appointment} interface instead.
	 */
	public static final String TABLE_NAME = "hd_Appointment";
	public static final Object[][] TABLE_COLUMNS = {
			{ "appointmentId", Types.BIGINT },
			{ "doctorId", Types.BIGINT },
			{ "patientId", Types.BIGINT },
			{ "appointmentDate", Types.TIMESTAMP },
			{ "appointmentTime", Types.INTEGER },
			{ "status", Types.INTEGER },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP }
		};
	public static final String TABLE_SQL_CREATE = "create table hd_Appointment (appointmentId LONG not null primary key,doctorId LONG,patientId LONG,appointmentDate DATE null,appointmentTime INTEGER,status INTEGER,createDate DATE null,modifiedDate DATE null)";
	public static final String TABLE_SQL_DROP = "drop table hd_Appointment";
	public static final String ORDER_BY_JPQL = " ORDER BY appointment.appointmentDate ASC, appointment.appointmentTime ASC, appointment.status ASC";
	public static final String ORDER_BY_SQL = " ORDER BY hd_Appointment.appointmentDate ASC, hd_Appointment.appointmentTime ASC, hd_Appointment.status ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.hellodoctor.slayer.model.Appointment"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.hellodoctor.slayer.model.Appointment"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.hellodoctor.slayer.model.Appointment"),
			true);
	public static long APPOINTMENTDATE_COLUMN_BITMASK = 1L;
	public static long DOCTORID_COLUMN_BITMASK = 2L;
	public static long PATIENTID_COLUMN_BITMASK = 4L;
	public static long STATUS_COLUMN_BITMASK = 8L;
	public static long APPOINTMENTTIME_COLUMN_BITMASK = 16L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Appointment toModel(AppointmentSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Appointment model = new AppointmentImpl();

		model.setAppointmentId(soapModel.getAppointmentId());
		model.setDoctorId(soapModel.getDoctorId());
		model.setPatientId(soapModel.getPatientId());
		model.setAppointmentDate(soapModel.getAppointmentDate());
		model.setAppointmentTime(soapModel.getAppointmentTime());
		model.setStatus(soapModel.getStatus());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Appointment> toModels(AppointmentSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Appointment> models = new ArrayList<Appointment>(soapModels.length);

		for (AppointmentSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.hellodoctor.slayer.model.Appointment"));

	public AppointmentModelImpl() {
	}

	@Override
	public long getPrimaryKey() {
		return _appointmentId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setAppointmentId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _appointmentId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Class<?> getModelClass() {
		return Appointment.class;
	}

	@Override
	public String getModelClassName() {
		return Appointment.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("appointmentId", getAppointmentId());
		attributes.put("doctorId", getDoctorId());
		attributes.put("patientId", getPatientId());
		attributes.put("appointmentDate", getAppointmentDate());
		attributes.put("appointmentTime", getAppointmentTime());
		attributes.put("status", getStatus());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long appointmentId = (Long)attributes.get("appointmentId");

		if (appointmentId != null) {
			setAppointmentId(appointmentId);
		}

		Long doctorId = (Long)attributes.get("doctorId");

		if (doctorId != null) {
			setDoctorId(doctorId);
		}

		Long patientId = (Long)attributes.get("patientId");

		if (patientId != null) {
			setPatientId(patientId);
		}

		Date appointmentDate = (Date)attributes.get("appointmentDate");

		if (appointmentDate != null) {
			setAppointmentDate(appointmentDate);
		}

		Integer appointmentTime = (Integer)attributes.get("appointmentTime");

		if (appointmentTime != null) {
			setAppointmentTime(appointmentTime);
		}

		Integer status = (Integer)attributes.get("status");

		if (status != null) {
			setStatus(status);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}
	}

	@JSON
	@Override
	public long getAppointmentId() {
		return _appointmentId;
	}

	@Override
	public void setAppointmentId(long appointmentId) {
		_appointmentId = appointmentId;
	}

	@JSON
	@Override
	public long getDoctorId() {
		return _doctorId;
	}

	@Override
	public void setDoctorId(long doctorId) {
		_columnBitmask |= DOCTORID_COLUMN_BITMASK;

		if (!_setOriginalDoctorId) {
			_setOriginalDoctorId = true;

			_originalDoctorId = _doctorId;
		}

		_doctorId = doctorId;
	}

	public long getOriginalDoctorId() {
		return _originalDoctorId;
	}

	@JSON
	@Override
	public long getPatientId() {
		return _patientId;
	}

	@Override
	public void setPatientId(long patientId) {
		_columnBitmask |= PATIENTID_COLUMN_BITMASK;

		if (!_setOriginalPatientId) {
			_setOriginalPatientId = true;

			_originalPatientId = _patientId;
		}

		_patientId = patientId;
	}

	public long getOriginalPatientId() {
		return _originalPatientId;
	}

	@JSON
	@Override
	public Date getAppointmentDate() {
		return _appointmentDate;
	}

	@Override
	public void setAppointmentDate(Date appointmentDate) {
		_columnBitmask = -1L;

		if (_originalAppointmentDate == null) {
			_originalAppointmentDate = _appointmentDate;
		}

		_appointmentDate = appointmentDate;
	}

	public Date getOriginalAppointmentDate() {
		return _originalAppointmentDate;
	}

	@JSON
	@Override
	public int getAppointmentTime() {
		return _appointmentTime;
	}

	@Override
	public void setAppointmentTime(int appointmentTime) {
		_columnBitmask = -1L;

		_appointmentTime = appointmentTime;
	}

	@JSON
	@Override
	public int getStatus() {
		return _status;
	}

	@Override
	public void setStatus(int status) {
		_columnBitmask = -1L;

		if (!_setOriginalStatus) {
			_setOriginalStatus = true;

			_originalStatus = _status;
		}

		_status = status;
	}

	public int getOriginalStatus() {
		return _originalStatus;
	}

	@JSON
	@Override
	public Date getCreateDate() {
		return _createDate;
	}

	@Override
	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	@Override
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	@Override
	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Appointment.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Appointment toEscapedModel() {
		if (_escapedModel == null) {
			_escapedModel = (Appointment)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelInterfaces, new AutoEscapeBeanHandler(this));
		}

		return _escapedModel;
	}

	@Override
	public Object clone() {
		AppointmentImpl appointmentImpl = new AppointmentImpl();

		appointmentImpl.setAppointmentId(getAppointmentId());
		appointmentImpl.setDoctorId(getDoctorId());
		appointmentImpl.setPatientId(getPatientId());
		appointmentImpl.setAppointmentDate(getAppointmentDate());
		appointmentImpl.setAppointmentTime(getAppointmentTime());
		appointmentImpl.setStatus(getStatus());
		appointmentImpl.setCreateDate(getCreateDate());
		appointmentImpl.setModifiedDate(getModifiedDate());

		appointmentImpl.resetOriginalValues();

		return appointmentImpl;
	}

	@Override
	public int compareTo(Appointment appointment) {
		int value = 0;

		value = DateUtil.compareTo(getAppointmentDate(),
				appointment.getAppointmentDate());

		if (value != 0) {
			return value;
		}

		if (getAppointmentTime() < appointment.getAppointmentTime()) {
			value = -1;
		}
		else if (getAppointmentTime() > appointment.getAppointmentTime()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		if (getStatus() < appointment.getStatus()) {
			value = -1;
		}
		else if (getStatus() > appointment.getStatus()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof Appointment)) {
			return false;
		}

		Appointment appointment = (Appointment)obj;

		long primaryKey = appointment.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		AppointmentModelImpl appointmentModelImpl = this;

		appointmentModelImpl._originalDoctorId = appointmentModelImpl._doctorId;

		appointmentModelImpl._setOriginalDoctorId = false;

		appointmentModelImpl._originalPatientId = appointmentModelImpl._patientId;

		appointmentModelImpl._setOriginalPatientId = false;

		appointmentModelImpl._originalAppointmentDate = appointmentModelImpl._appointmentDate;

		appointmentModelImpl._originalStatus = appointmentModelImpl._status;

		appointmentModelImpl._setOriginalStatus = false;

		appointmentModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Appointment> toCacheModel() {
		AppointmentCacheModel appointmentCacheModel = new AppointmentCacheModel();

		appointmentCacheModel.appointmentId = getAppointmentId();

		appointmentCacheModel.doctorId = getDoctorId();

		appointmentCacheModel.patientId = getPatientId();

		Date appointmentDate = getAppointmentDate();

		if (appointmentDate != null) {
			appointmentCacheModel.appointmentDate = appointmentDate.getTime();
		}
		else {
			appointmentCacheModel.appointmentDate = Long.MIN_VALUE;
		}

		appointmentCacheModel.appointmentTime = getAppointmentTime();

		appointmentCacheModel.status = getStatus();

		Date createDate = getCreateDate();

		if (createDate != null) {
			appointmentCacheModel.createDate = createDate.getTime();
		}
		else {
			appointmentCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			appointmentCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			appointmentCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		return appointmentCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(17);

		sb.append("{appointmentId=");
		sb.append(getAppointmentId());
		sb.append(", doctorId=");
		sb.append(getDoctorId());
		sb.append(", patientId=");
		sb.append(getPatientId());
		sb.append(", appointmentDate=");
		sb.append(getAppointmentDate());
		sb.append(", appointmentTime=");
		sb.append(getAppointmentTime());
		sb.append(", status=");
		sb.append(getStatus());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(28);

		sb.append("<model><model-name>");
		sb.append("com.hellodoctor.slayer.model.Appointment");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>appointmentId</column-name><column-value><![CDATA[");
		sb.append(getAppointmentId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>doctorId</column-name><column-value><![CDATA[");
		sb.append(getDoctorId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>patientId</column-name><column-value><![CDATA[");
		sb.append(getPatientId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>appointmentDate</column-name><column-value><![CDATA[");
		sb.append(getAppointmentDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>appointmentTime</column-name><column-value><![CDATA[");
		sb.append(getAppointmentTime());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>status</column-name><column-value><![CDATA[");
		sb.append(getStatus());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Appointment.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] {
			Appointment.class
		};
	private long _appointmentId;
	private long _doctorId;
	private long _originalDoctorId;
	private boolean _setOriginalDoctorId;
	private long _patientId;
	private long _originalPatientId;
	private boolean _setOriginalPatientId;
	private Date _appointmentDate;
	private Date _originalAppointmentDate;
	private int _appointmentTime;
	private int _status;
	private int _originalStatus;
	private boolean _setOriginalStatus;
	private Date _createDate;
	private Date _modifiedDate;
	private long _columnBitmask;
	private Appointment _escapedModel;
}